<template>
	<!-- 供应单位 -->
	<div>
		<!-- 搜索供应单位 -->
		<div style="margin-top: 10%;">
			<van-field :value="source_name" center clearable placeholder="生产厂家搜索" :use-button-slot="true"
				left-icon="search" :border="false" @input="source_name_input">
			</van-field>
		</div>
		<!-- 供应单位列表 -->
		<div>
			<div v-for="(item, index) in sources" :key="index" style="margin-top: 5%;" @click="warehouse_back(item)">
					<van-cell-group inset>
					  <van-cell 
						:title="item.manufacturer" />
					</van-cell-group>
			</div>
		</div>
	</div>
</template>

<script>
	import { BaseUrl } from '@/util/util.js';
	const PrefixUrl = BaseUrl();
	export default {
		data(){
			return{
				source_name: '',
				sources: [],
				material_id: '',
				material_name: '',
				material_model: '',
			}
		},
		onLoad: function(option) {
			this.material_id = option.id;
			this.material_name = option.name;
			this.material_model = option.model;
			
		},
		created() {
			this.getSourceByBdst();
		},
		methods:{
			source_name_input(event) {
				this.source_name = event.detail;
				uni.request({
					method: 'POST',
					url: PrefixUrl + '/materialManufacturer/getManu',
					data: {
						bdst: uni.getStorageSync('userbdst'),
						manu_name: this.source_name
				
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'token': uni.getStorageSync('token')
					},
					success: (res) => {
						console.log(res)
						this.sources = res.data.obj;
					}
				});
			},
			getSourceByBdst(){
				uni.request({
					method: 'POST',
					url: PrefixUrl + '/materialManufacturer/getManu',
					data: {
						bdst: uni.getStorageSync('userbdst'),
						manu_name: this.source_name
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'token': uni.getStorageSync('token')
					},
					success: (res) => {
						console.log(res)
						this.sources = res.data.obj;
					}
				});
			},
			warehouse_back(item){
				uni.removeStorageSync("material_manuName");
				uni.setStorageSync("material_manuName", item.manufacturer);
				uni.redirectTo({
					url: '/pages/material/warehouse/warehouse_detail?id=' + this.material_id 
					+ '&name=' + this.material_name +  '&model=' + this.material_model
				});
			}
		}
	} 
</script>

<style>
</style>